//
//  HXTableCustonPlayerCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/8/30.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXTableCustonPlayerCell.h"
#import "HXCollectionCustomPlayerCell.h"
#import "HX_Macro.h"
#import "UIView+Frame.h"
#import "UIImageView+WebCache.h"
#import "HXCycleCellBigModel.h"
#import "HXCycleCellModel.h"
#import "HXCustomModel.h"
#import "HXCollecotionFlowLayout.h"
#import "UIView+MJExtension.h"
#import "UIView+BundleExtension.h"

@implementation HXTableCustonPlayerCell
- (void)setTitles:(NSMutableArray *)titles {
    _titles = titles;
}
- (void)setArrCustom:(NSMutableArray *)arrCustom {
    _arrCustom = arrCustom;
    [_collectionView reloadData];
}
- (void)setUp {
    HXCollecotionFlowLayout *layout = [[HXCollecotionFlowLayout alloc] init];
    layout.delegate = self;
      self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.scrollEnabled = YES;
    [self.contentView addSubview:_collectionView];
   [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HXCollectionCustomPlayerCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([HXCollectionCustomPlayerCell class])];
    [self creatView];
}
- (void)creatView {
    self.viewDetail = [[UILabel alloc] init];
    _viewDetail.backgroundColor = [UIColor colorWithRed:0.88 green:0.88 blue:0.88 alpha:1.00];
    [self.contentView addSubview:_viewDetail];
    self.labelDetail = [[UILabel alloc] init];
    self.labelDetail.font = [UIFont systemFontOfSize:12];
    self.labelDetail.textColor = [UIColor colorWithWhite:0.520 alpha:1.000];
    self.labelDetail.textAlignment = 1;
    _labelDetail.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_labelDetail];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    HXCollectionCustomPlayerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HXCollectionCustomPlayerCell class]) forIndexPath:indexPath];
    cell.backgroundColor = COLORAUTO;
    HXCustomModel *model = self.arrCustom[indexPath.row];
    [cell.imageBack sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", model.image]]];
    cell.imageBack.contentMode = UIViewContentModeScaleAspectFill;
    cell.imageBack.layer.masksToBounds = YES;
    if (indexPath.row == 0) {
    cell.labelTitle.text = [self.titles objectAtIndex:0];
    cell.lableDetail.text = [self.titles objectAtIndex:1];
    }
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
                   layout:(UICollectionViewLayout *)collectionViewLayout
                    width:(CGFloat)width
 heightForItemAtIndexPath:(NSIndexPath *)indexPath {
     return self.collectionView.HX_height / 2;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (void)layoutSubviews {
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 50);
    self.labelDetail.frame = CGRectMake(0,  _collectionView.HX_height, _collectionView.HX_width, 35);
     self.viewDetail.frame = CGRectMake(0, _collectionView.HX_height + self.labelDetail.HX_height, _collectionView.HX_width, 15);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.item(indexPath.row);
}
@end
